'use strict';
const db = uniCloud.database()
const $ = db.command.aggregate
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const {
		username
	} = event
	const userInfo = await db.collection('uni-id-users').where({
		username: username
	}).get()
	const cart = userInfo.data[0].cart
	const goods = await db.collection('goods-list').aggregate()
		.addFields({
			in_cart: $.in(['$_id', cart])
		}).end()
	// const res = await goods.get(event)
	//返回数据给客户端
	const goodsList = goods.data
	let cartList = []
	goodsList.forEach(item => {
		if (item.in_cart == true) {
			cartList.push(item)
		}
	})
	console.log(cartList)
	return cartList
};
